package com.anuyun.ms.base.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.anuyun.ms.base.config.property.FeatureProperty;
import com.anuyun.ms.base.filter.AuthFilter;

@Configuration
public class RestFilterConfig {
	
	@Autowired
	private AuthFilter authFilter;
	
	/**
	 * 虽然是静态用法，但也必须要注入 提高FeatureProperty生成优先级
	 */
	@Autowired
	@SuppressWarnings("unused")
	private FeatureProperty featureProperty;
	
	
	
	@Bean
    public FilterRegistrationBean<AuthFilter> filterRegistrationBean() {
        FilterRegistrationBean<AuthFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(authFilter);

        registrationBean.addUrlPatterns("*");
        registrationBean.setOrder(1);
        registrationBean.setEnabled(FeatureProperty.AUTH);

        return registrationBean;
    }
		
	
}
